package com.livrexpress.livrexpressandroid.localdomain;
import android.app.Application;
import android.content.Context;
import android.widget.Toast;

import com.livrexpress.livrexpressandroid.activity.MainActivity;
import com.livrexpress.livrexpressandroid.localdomain.DataManager;


public class LivreApplication extends Application{
    private static DataManager sqliteManager;
    private static  Context currentContext = null; 
    
    @Override
    public void onCreate(){
        super.onCreate();
        LivreApplication.currentContext = getApplicationContext();
    }

    public static DataManager getSqliteManager() {
        if(sqliteManager == null) {
            sqliteManager = new DataManager(currentContext);
        }
        
        return sqliteManager;
    }

    public static void setCurrentContext(Context currentContext) {
        LivreApplication.currentContext = currentContext;
    }

    public static Context getCurrentContext() {
        return currentContext;
    }
    @Override
    protected void finalize() throws Throwable
    {
        super.finalize();
        sqliteManager.closeDB();
        Toast.makeText(currentContext, "close db", Toast.LENGTH_LONG).show();
    }
}